<%-- 
    Document   : index
    Author     : Jagadeesh
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="model.UserBean" %>
<%@page import="java.sql.*"%>
<%@page import="database.DBClass"%>
<%@page import="java.util.List"%>
<link rel="stylesheet" href="css/bootstrap.css">
<%
    if (session.getAttribute("userName") == null) {

        RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
        rd.forward(request, response);
    }

    UserBean bean;
    bean = new UserBean();
    //get request from servlet if data is invalid
    if (request.getAttribute("error") != null) {
        bean = (UserBean) request.getAttribute("error");
    }
    if (request.getAttribute("updateuser") != null) {
        bean = (UserBean) request.getAttribute("updateuser");
    }
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="js/show.js"></script>

        <title>JSP Page</title>
    </head>
    <body>
        <center>
            <h1>Add User</h1>

            <form method="post" action="ControllerServlet">

                <TABLE border="0"width="600px">
                    <TR>
                        <TD width="150px">Fullname:</TD>
                        <TD>
                            <INPUT TYPE="text" NAME="fullName" value="<%=bean.getfullName()%>">
                        </TD>
                        <TD width="350px">
                            <font color="red"><%=bean.getfullNameError()%> &nbsp;</font>
                        </TD>
                    </TR>
                    <TR>
                        <TD width="150px">Username:</TD>
                        <TD>
                            <INPUT TYPE="text" NAME="userName" value="<%=bean.getUserName()%>" <%=request.getAttribute("updateuser") != null ? "readonly" : ""%>>
                        </TD>
                        <TD width="350px">
                            <font color="red"><%=bean.getUserNameError()%> &nbsp;</font>
                        </TD>
                    </TR>
                    <TR>
                        <TD width="150px">Password:</TD>
                        <TD>
                            <INPUT TYPE="password" NAME="password" value="<%=bean.getPassword()%>">
                        </TD>
                        <TD width="350px">
                            <font color="red"><%=bean.getPasswordError()%> &nbsp;</font>
                        </TD>
                    </TR>
                    <TR>
                        <TD width="150px">Date Of Birth:</TD>
                        <TD>
                            <INPUT TYPE="text" NAME="dateOfBirth" value="<%=bean.getDateOfBirth()%>">
                        </TD>
                        <TD>
                            <font color="red"><%=bean.getDateOfBirthError()%> </font>
                        </TD>
                    </TR>
                    <TR>
                        <TD width="150px">E-Mail :</TD>
                        <TD>
                            <INPUT TYPE="text" NAME="email" value="<%=bean.getEmail()%>">
                        </TD>
                        <TD>
                            <font color="red"><%=bean.getEmailError()%> </font>
                        </TD>
                    </TR>
                    <TR>
                        <TD width="150px">Phone no:</TD>
                        <TD>
                            <INPUT TYPE="text" NAME="phoneNo" value="<%=bean.getPhoneNo()%>">
                        </TD>
                        <TD>
                            <font color="red"><%=bean.getPhoneNoError()%> </font>
                        </TD>
                    </TR>
                    <TR>
                        <TD width="150px">Provinsi:</TD>
                        <TD>
                            <select name='provinsi' onchange="showKabupaten(this.value)">  
                                <option value="none">Select</option>  
                                <%
                                    DBClass dbobject = new DBClass();
                                    List list = dbobject.getJenis();
                                    request.setAttribute("list", list);
                                    List list2 = (List) request.getAttribute("list");
                                    if (list2 != null) {
                                        for (int i = 0; i < list2.size(); i++) {
                                            UserBean ubean = (UserBean) list2.get(i);
                                %>
                                <option value="<%=ubean.getIdJenis()%>"><%= ubean.getNamaJenis()%></option>  
                                <%
                                        }
                                    }
                                %>
                            </select>  
                        </TD>
                        <TD>

                        </TD>
                    </TR>
                    <TR>
                        <TD width="150px">Kabupaten:</TD>
                        <TD>
                            <div id='kabupaten'>  

                                <select name='kabupaten' >  
                                    <option value='-1'></option>  

                                </select>  
                            </div>  
                        </TD>
                        <TD>

                        </TD>
                    </TR>
                    <TR>
                        <TD width="150px">Kecamatan:</TD>
                        <TD>
                            <div id='kecamatan'>  
                                <select name='kecamatan' >  
                                    <option value='-1'></option>  
                                </select>  
                            </div>
                        </TD>
                        <TD>

                        </TD>
                    </TR>
                    <TR>
                        <TD width="150px">Desa:</TD>
                        <TD>
                            <div id='desa'>  
                                <select name='desa' >  
                                    <option value='-1'></option>  
                                </select>  
                            </div>
                        </TD>
                        <TD>

                        </TD>
                    </TR>
                    <TR>
                        <TD colspan="2" align="center">

                            <INPUT TYPE="submit" class="btn btn-primary" value="<%=bean.getAction()%>" name="action"></input>

                            <a class="btn btn-default" href="ControllerServlet?action=cancel">Cancel</a>

                        </TD>
                        <TD>
                            &nbsp;
                        </TD>
                    </TR>

                </TABLE>

            </form>

        </center>
    </body>
</html>
